<div class="leftbody">
    <section class="col-md-8 col-sm-12 col-xs-12" ng-controller="forgetPsdCtrl">
        <form name="rePsdForm" class="form-horizontal" ng-submit="rePsdFormSub(rePsdForm.$valid)" novalidate>
            <h3><a href="/">主页</a>/找回密码 &nbsp;<small class="text-danger hide" id="errorPsd">邮箱不正确</small></h3>
            <div class="form-group">
                <label for="userName" class="col-sm-2 control-label">用户名</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" name="userName" id="userName" ng-minlength="6" ng-maxlength="12" ng-model="rePsdFormData.userName" ng-pattern="/^[a-zA-Z][a-zA-Z0-9_]{5,11}$/" placeholder="请输入用户名" required>
                    <label ng-cloak for="inputError" class="control-label text-danger" ng-show="rePsdForm.userName.$invalid && !rePsdForm.userName.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>用户名为6-12个英文数字组合</label>
                </div>
            </div>
            <div class="form-group">
                <label for="email" class="col-sm-2 control-label">注册邮箱</label>
                <div class="col-sm-6">
                    <input type="email" class="form-control" name="email" id="email" ng-model="rePsdFormData.email" ng-pattern="/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/" placeholder="请输入邮箱地址" required>
                    <label ng-cloak for="inputError" class="control-label text-danger" ng-show="rePsdForm.email.$invalid && !rePsdForm.email.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>请输入正确的邮箱地址</label>
                </div>
            </div>
            <div class="form-group">
                <label for="newPassword" class="col-sm-2 control-label">新密码</label>
                <div class="col-sm-6">
                    <input type="password" class="form-control" id="newPassword" name="newPassword"placeholder="请输入新密码" ng-pattern="/[?!a-zA-Z0-9_]{6,16}/" ng-maxlength="16" ng-model="rePsdFormData.newPassword" required>
                    <label ng-cloak for="inputError" class="control-label text-danger" ng-show="rePsdForm.newPassword.$invalid && !rePsdForm.newPassword.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>6-16位，只能包含字母数字下划线</label>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button class="btn btn-success" ng-disabled="rePsdForm.$invalid">更改密码</button>
                </div>
            </div>
        </form>
    </section>
    <section>
        <%- include rightmain%>
    </section>
</div>
<script>
    var webApp = angular.module('webApp',[]);
    webApp.controller('forgetPsdCtrl',function ($scope,$http) {
        $scope.rePsdFormSub = function (isVaild) {
            if(isVaild){
                //如果表单内容格式正确
                $http({
                    method:'POST',
                    url:'/users/getPsd',
                    data:$.param($scope.rePsdFormData),
                    headers:{'Content-Type':'application/x-www-form-urlencoded'}
                }).success(function (data) {
                    console.log(data);
                    if(data === 'success'){
                        alert('密码修改成功,现在可以登录');
                        window.location = '/users/login';
                    } else {
                        $('#errorPsd').removeClass('hide').text(data);
                    }
                })
            } else {
                alert('输入有误！');
            }
        }
    })
</script>